package com.snailthink.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpSession;

@Controller
@RequestMapping("/user")
public class UserLoginController {

    @RequestMapping("/main")
    public String main(){
        return "main";
    }
    @RequestMapping("/goLogin")
    public String goLogin(){
        return "login";
    }

    @RequestMapping("/hello")
    public String hello(HttpSession session, String userName, String password) {
        session.setAttribute("userLoginInfo",userName);
        return "main";
    }


    /**
     * 登陆提交
     * @param session
     * @param username
     * @param pwd
     * @return
     * @throws Exception
     */
    @RequestMapping("/login")
    public String login(HttpSession session, String username, String pwd) throws Exception {
        // 向session记录用户身份信息
        System.out.println("接收前端==="+username);
        session.setAttribute("user", username);
        return "success";
    }

    /**
     * 退出登陆
     * @param session
     * @return
     * @throws Exception
     */
    @RequestMapping("logout")
    public String logout(HttpSession session) throws Exception {
        // session 过期
        session.invalidate();
        return "login";
    }

}
